package com.huike.web.controller.report;

import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.contract.domain.TbContract;
import com.huike.contract.service.ContractService;
import com.huike.report.domain.vo.*;
import com.huike.clues.domain.TbActivity;
import com.huike.clues.domain.TbClue;
import com.huike.common.core.controller.BaseController;
import com.huike.report.domain.vo.ActivityStatisticsVo;
import com.huike.report.domain.vo.IndexBaseInfoVO;
import com.huike.report.domain.vo.IndexTodayInfoVO;
import com.huike.report.domain.vo.IndexTodoInfoVO;
import com.huike.report.domain.vo.TigerDragonDTO;
import com.huike.report.service.IReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.huike.report.service.IReportService;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Description TODO
 * @Author hzh
 * @Date 2023-07-13 8:28
 */

/**
 * @author STJ12138
 * @version 1.0
 * @description: TODO
 * @date 2023/7/13 9:05
 */
@RestController
@RequestMapping("/report")
@Api(tags = "统计分析相关接口")
@Slf4j
public class ReportController extends BaseController {

    @Resource
    private IReportService reportService;
    @Resource
    private ContractService contractService;

    /**
     * 渠道统计活动明细列表
     *
     * @param tbActivity
     * @return
     */
    @GetMapping("/activityStatisticsList")
    @ApiOperation("渠道统计活动明细列表")
    public TableDataInfo<List<TbClue>> activityStatisticsList(TbActivity tbActivity) {
        startPage();
        List<ActivityStatisticsVo> returnList = reportService.activityStatisticsList(tbActivity);
        return getDataTable(returnList);
    }

    /**
     * 线索统计明细列表
     *
     * @param tbClue
     * @return
     */
    @GetMapping("/cluesStatisticsList")
    @ApiOperation("线索统计明细列表")
    public TableDataInfo<List<TbClue>> cluesStatisticsList(TbClue tbClue) {
        startPage();

        List<TbClue> returnList = reportService.cluesStatisticsList(tbClue);
        return getDataTable(returnList);
    }


    /**
     * 基础数据统计
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/channelStatisticsList/{beginCreateTime}/{endCreateTime}")
    @ApiOperation("销售统计归属渠道明细列表")
    public TableDataInfo<List<ReportSalesChannelStatisticsListDataVo>> channelStatisticsList(@PathVariable String beginCreateTime,
                                                                                             @PathVariable String endCreateTime) {
        TableDataInfo<List<ReportSalesChannelStatisticsListDataVo>> returnList = reportService.channelStatisticsList(beginCreateTime, endCreateTime);
        return returnList;
    }


    /**
     * @description: 客户统计新增客户数报表
     * @param: beginCreateTime
     * endCreateTime
     * @return: com.huike.report.domain.vo.LineChartVo
     * @author STJ12138
     * @date: 2023/7/13 9:29
     */
    @GetMapping("/contractStatistics/{beginCreateTime}/{endCreateTime}")
    @ApiOperation("客户统计新增客户数报表")
    public LineChartVo contractStatisticsChart(@PathVariable String beginCreateTime, @PathVariable String endCreateTime) {
        log.info("beginCreateTime:{},endCreateTime:{}", beginCreateTime, endCreateTime);
        LineChartVo chartVo = reportService.contractStatisticsChart(beginCreateTime, endCreateTime);
        return chartVo;
    }

    /**
     * @description: 客户统计明细列表
     * @param: tbContract
     * @return: com.huike.common.core.page.TableDataInfo<java.util.List < com.huike.contract.domain.TbContract>>
     * @author STJ12138
     * @date: 2023/7/13 14:49
     */
    @GetMapping("/contractStatisticsList")
    @ApiOperation("客户统计明细列表")
    public TableDataInfo<List<TbContract>> contractStatisticsList(TbContract tbContract) {
        tbContract.setStatus("4");
        TableDataInfo<List<TbContract>> tableDataInfo = contractService.list(tbContract);
        return tableDataInfo;
    }

    /**
     * @description: 销售统计归属部门明细列表
     * @param: beginCreateTime
     * endCreateTime
     * @return: com.huike.common.core.page.TableDataInfo<java.util.List < com.huike.web.result.ReportSalesDeptStatisticsListData>>
     * @author STJ12138
     * @date: 2023/7/13 14:56
     */
    @GetMapping("/deptStatisticsList/{beginCreateTime}/{endCreateTime}")
    @ApiOperation("销售统计归属部门明细列表")
    public TableDataInfo<List<ReportSalesDeptStatisticsListDataVo>> deptStatisticsList(@PathVariable String beginCreateTime, @PathVariable String endCreateTime) {
        TableDataInfo<List<ReportSalesDeptStatisticsListDataVo>> tableDataInfo = reportService.deptStatisticsList(beginCreateTime, endCreateTime);
        return tableDataInfo;
    }

    /**
     * @description: 销售统计归属人报表
     * @param: beginCreateTime
    endCreateTime
     * @return: com.huike.common.core.page.TableDataInfo<java.util.List<com.huike.report.domain.vo.ReportSalesOwnerShipStatisticsListDataVo>>
     * @author STJ12138
     * @date: 2023/7/13 16:07
     */
    @GetMapping("/ownerShipStatisticsList/{beginCreateTime}/{endCreateTime}")
    @ApiOperation("销售统计归属人报表")
    public TableDataInfo<List<ReportSalesOwnerShipStatisticsListDataVo>> ownerShipStatisticsList(@PathVariable String beginCreateTime, @PathVariable String endCreateTime){
        TableDataInfo<List<ReportSalesOwnerShipStatisticsListDataVo>> tableDataInfo = reportService.ownerShipStatisticsList(beginCreateTime,endCreateTime);
        return tableDataInfo;
    }

    @GetMapping("/getBaseInfo")
    public AjaxResult getBaseInfo(String beginCreateTime, String endCreateTime) {
        IndexBaseInfoVO indexBaseInfoVO = reportService.getBaseInfo(beginCreateTime, endCreateTime);
        return AjaxResult.success(indexBaseInfoVO);
    }

    /**
     * 获取今日简报数据
     *
     * @return
     */
    @GetMapping("/getTodayInfo")
    public AjaxResult getTodayInfo() {
        IndexTodayInfoVO indexTodayInfoVO = reportService.getTodayInfo();
        return AjaxResult.success(indexTodayInfoVO);
    }

    /**
     * 获取待办数据
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/getTodoInfo")
    public AjaxResult getTodoInfo(String beginCreateTime, String endCreateTime) {
        IndexTodoInfoVO indexTodoInfoVO = reportService.getTodoInfo(beginCreateTime, endCreateTime);
        return AjaxResult.success(indexTodoInfoVO);
    }


    /**
     * @description: 销售统计报表
     * @param: beginCreateTime
     * endCreateTime
     * @return: com.huike.report.domain.vo.LineChartVo
     * @author STJ12138
     * @date: 2023/7/13 17:11
     */
    @GetMapping("/salesStatistics/{beginCreateTime}/{endCreateTime}")
    @ApiOperation("销售统计报表")
    public LineChartVo salesStatistics(@PathVariable String beginCreateTime, @PathVariable String endCreateTime) {
        LineChartVo lineChartVo = reportService.salesStatistics(beginCreateTime, endCreateTime);
        return lineChartVo;
    }

    /**
     * @description: 客户统计学科分布统计报表
     * @param: beginCreateTime
     * endCreateTime
     * @return: com.huike.common.core.domain.AjaxResult<java.util.List < com.huike.report.domain.vo.ReportSubjectStatisticsDataVo>>
     * @author STJ12138
     * @date: 2023/7/13 17:32
     */
    @GetMapping("/subjectStatistics/{beginCreateTime}/{endCreateTime}")
    @ApiOperation("客户统计学科分布统计报表")
    public AjaxResult<List<ReportSubjectStatisticsDataVo>> subjectStatistics(@PathVariable String beginCreateTime, @PathVariable String endCreateTime) {
        List<ReportSubjectStatisticsDataVo> list = reportService.subjectStatistics(beginCreateTime, endCreateTime);
        return AjaxResult.success(list);
    }

    /**
     * @description: 线索统计线索转换率报表
     * @param: beginCreateTime
     * endCreateTime
     * @return: com.huike.common.core.domain.AjaxResult<com.huike.report.domain.vo.VulnerabilityMapVo>
     * @author STJ12138
     * @date: 2023/7/13 18:58
     */
    @GetMapping("/getVulnerabilityMap/{beginCreateTime}/{endCreateTime}")
    @ApiOperation("线索统计线索转换率报表")
    public AjaxResult<VulnerabilityMapVo> getVulnerabilityMap(@PathVariable String beginCreateTime, @PathVariable String endCreateTime) {
        VulnerabilityMapVo vulnerabilityMapVo = reportService.getVulnerabilityMap(beginCreateTime, endCreateTime);
        return AjaxResult.success(vulnerabilityMapVo);
    }

    /**
     * 线索转换龙虎榜
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/salesStatistic")
    @ApiOperation("线索转换龙虎榜")
    public AjaxResult salesStatistic(String beginCreateTime, String endCreateTime) {

        List<TigerDragonDTO> tigerDragonDTOList = reportService.salesStatistic(beginCreateTime, endCreateTime);
        return AjaxResult.success(tigerDragonDTOList);

    }


    /**
     * 商机转换龙虎榜
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @ApiOperation("商机转换龙虎榜")
    @GetMapping("/businessChangeStatistics")
    public AjaxResult businessChangeStatistics(String beginCreateTime, String endCreateTime) {
        List<TigerDragonDTO> tigerDragonDTOList = reportService.businessChangeStatistics(beginCreateTime, endCreateTime);
        return AjaxResult.success(tigerDragonDTOList);
    }
}
